import request from '@/utils/request';
import { AxiosPromise } from 'axios';

/**
 * 获取后台开关
 * @returns {*}
 */
export const wsEnabled = (): AxiosPromise<any> => {
  return request({
    url: '/resource/websocket/getEnabled',
    method: 'get'
  });
};

/**
 * 指定发送信息
 * @param userId
 * @param message
 * @returns {*}
 */
export const wsSend = (userId: number | string, message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/websocket/send?userId=' + userId + '&message=' + message,
    method: 'get'
  });
};

/**
 * 指定发送信息
 * @param message
 * @returns {*}
 */
export const wsSendAll = (message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/websocket/sendAll?message=' + message,
    method: 'get'
  });
};

/**
 * 订阅主题
 * @param topic
 * @returns {*}
 */
export const wsSubscribe = (topic: string): AxiosPromise<any> => {
  return request({
    url: '/resource/websocket/subscribe?topic=' + topic,
    method: 'get'
  });
};

/**
 * 群发websocket订阅消息
 * @param topic
 * @param userIds
 * @param message
 * @returns {*}
 */
export const wsPublish = (topic: string, userIds: (number | string)[], message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/websocket/publishAll?topic=' + topic + '&userIds=' + userIds + '&message=' + message,
    method: 'get'
  });
};

/**
 * 群发websocket订阅消息
 * @param topic
 * @param message
 * @returns {*}
 */
export const wsPublishAll = (topic: string, message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/websocket/publishAll?topic=' + topic + '&message=' + message,
    method: 'get'
  });
};
